<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>功能管理</title>
    <link rel="stylesheet" href="./layui/css/layui.css" media="all">
</head>
<body>
<blockquote class="layui-elem-quote quoteBox">
    <form class="layui-form">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" class="layui-input searchName" placeholder="名称" />
            </div>
            <a class="layui-btn search_btn" data-type="reload">搜索</a>
        </div>
        <div class="layui-inline">
            <a class="layui-btn layui-btn-normal addNews_btn">添加功能</a>
        </div>
        <div class="layui-inline">
            <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
        </div>
    </form>
</blockquote>

<table id="actionList" lay-filter="actionTable" ></table>

<script type="text/html" id="actionListBar">
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>



<script src="./layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->


<script type="text/javascript" charset="utf-8">
    layui.use(
        [ "table", "jquery" ],
        function() {
            var table = layui.table, $ = layui.$;

            var tableIns = table.render({
                elem : '#actionList',
                cols : [ [ {
                    type : 'checkbox'
                },{
                    field : "actionId",
                    title : "功能id",
                    align : "center",
                    sort: true
                },{
                    field : "actionName",
                    title : "功能名称",
                    align : "center",
                    sort: true
                },  {
                    field : "url",
                    title : "功能地址",
                    align : "center"
                },{
                    field : "parentId",
                    title : "父结点",
                    align : "center",
                    sort: true
                },{
                    title : "操作",
                    width : 170,
                    fixed : "right",
                    align : "center",
                    toolbar : "#actionListBar"
                } ] ],
                url : '/evaluation/action/list',
                cellMinWidth : 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                page : true,
                limits : [ 3, 5, 10 ],
            });

            //搜索, 条件查询
            $(".search_btn").on("click", function() {
                tableIns.reload({
                    page : {
                        curr : 1
                        //重新从第 1 页开始  ,！！！！！！！！！！！！！！备注：我用springboot在这里栽了跟头
                    },
                    where : {
                        actionName : encodeURI($(".searchName").val())

                        //搜索的关键字
                        /*   , code: $(".searchCode").val()  //搜索的关键字 */
                    }
                });
            });



            //添加新功能
            function addNews(location) {
                var index = layui.layer.open({
                    title: "功能",
                    type: 2,
                    anim:3  ,
                    maxmin:true,
                    content: location,
                    end: function () {
                        tableIns.reload({
                            page : {
                                curr : 1
                                //重新从第 1 页开始
                            },

                        })
                    },
                    success: function (layero, index) {
                        layui.layer.getChildFrame('body', index);
                        setTimeout(function () {
                            layui.layer.tips('点击此处返回客户列表', '.layui-layer-setwin .layui-layer-close ', {
                                tips: 3
                            });
                        }, 500)
                    },

                })
                layui.layer.full(index);

            }


            $(".addNews_btn").click(function () {
                var location = "actionedit.html";
                addNews(location);
            });

            //监听工具条
            table.on('tool(actionTable)', function(obj) {//注：tool是工具条事件名，demo是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data;//获得当前行数据
                if (obj.event === 'detail') {//获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                    layer.alert(JSON.stringify(data));
                } else if (obj.event === 'del') {
                    layer.confirm('真的删除行么', {
                        icon : 3,
                        title : '提示信息'
                    }, function(index) {
                        obj.del();//删除对应行（tr）的DOM结构，并更新缓存
                        //向服务端发送删除指令
                        $.post("/evaluation/action/delete", {
                            id : data.actionId
                            //将需要删除的newsId作为参数传入
                        }, function(data) {
                            tableIns.reload();
                            layer.close(index);
                        })
                    });
                } else if (obj.event === 'edit') {
                    var location = "actionedit.html?actionId="+ data.actionId;
                    addNews(location);
                }
            });

            // 批量删除
            $(".delAll_btn").click(
                function() {
                    var checkStatus = table.checkStatus('actionList'), data = checkStatus.data, checkedList = [];
                    if (data.length > 0) {
                        for ( var i in data) {
                            checkedList.push(data[i].actionId);
                        }
                        layer.confirm(
                            '确定删除选中的信息？',
                            {
                                icon : 3,
                                title : '提示信息'
                            },
                            function(index) {
                                $.post(
                                    "/evaluation/action/delete",
                                    {
                                        "delitems" : checkedList.toString()
                                    },
                                    function(data) {
                                        tableIns.reload();
                                        layer.close(index);
                                    })
                            })
                    } else {
                        layer.msg("请选择需要删除的信息");
                    }
                });
        });
</script>
</body>
</html>